//
//  Int64+XFExtension.swift
//  XFDownload
//
//  Created by mac on 2018/10/29.
//  Copyright © 2018 zeroLu. All rights reserved.
//

import Foundation

extension Int64 {
    
    func toStringSize(countStyle: ByteCountFormatter.CountStyle = .binary,
                           allowZero: Bool = false,
                           units: ByteCountFormatter.Units = [ByteCountFormatter.Units.useKB, ByteCountFormatter.Units.useMB, ByteCountFormatter.Units.useGB],
                           zeroDigits: Bool = true) -> String {
        
        if self == 0 {
            return "0KB"
        }
        
        let byteFormatter = ByteCountFormatter()
        byteFormatter.countStyle = countStyle
        byteFormatter.allowsNonnumericFormatting = allowZero
        byteFormatter.allowedUnits = units
        byteFormatter.zeroPadsFractionDigits = zeroDigits
        
        let size = byteFormatter.string(fromByteCount: Int64(self))
        
        return size
        
    }
    
}
